import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { HelloEntity } from './hello.entity';
import { BasicService } from 'src/basic/basic.service';
import HelloDto from './hello.dto';

@Injectable()
export class HelloService extends BasicService<HelloDto> {
  constructor(
    @InjectRepository(HelloEntity)
    private readonly postsRepository: Repository<HelloEntity>,
  ) {
    super(postsRepository);
  }

  async getAll(): Promise<HelloDto[]> {
    return await this.list();
  }

  async getById(id: number): Promise<HelloDto> {
    const p = await this.info(id);
    if (!p) {
      this.fail(`id为${id}的文章不存在`, 401);
    }
    return p;
  }
}
